package com.company;


import java.util.Random;
import java.util.Scanner;

/**
 * @author 10277
 */
public class GuessNumber {
    public static void menu() {
        System.out.println("------------------");
        System.out.println("------1.Play------");
        System.out.println("------2.Exit------");
        System.out.println("------------------");
    }

    public static void game() {
        Random random = new Random();
        int guess = random.nextInt(10) + 1;
        Scanner scanner = new Scanner(System.in);
        int i = 0;
        while (true) {
            System.out.println("请输入你猜到的数字");
            int number = scanner.nextInt();
            i = i + 1;
            if (guess < number) {
                System.out.println("猜大了");
            } else if (guess > number) {
                System.out.println("猜小了");
            } else {
                System.out.println("恭喜你！猜对了" + "你一共猜了" + i + "次");
                break;
            }
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int input;
        do {
            menu();
            System.out.println("请输入");
            input = scanner.nextInt();
            switch (input) {
                case 1: {
                    game();
                    break;
                }
                case 2: {
                    System.out.println("游戏结束");
                    break;
                }
                default: {
                    System.out.println("请输入正确的数字");
                    break;
                }
            }
        }
        while (input < 1);
    }

}
